/**
 *
 */
var path = '../';
var pageListUrl = path + 'equipment/list';
var pageUrl = path + 'equipment/';

$(function () {
    $(document).keyup(function (e) {
        if (e.which == 13) {
            $('#selectBtnEnter').click();
        }
    })
});
//添加弹窗
var addPanel = null;
// ---------------交互代码begin-----------------
//本页面业务逻辑
var dictType = {
    checkLogic: function (dataObj) {
        var result = "";
        var isSubmit = true;
        console.log(dataObj);
        var equipmentCode = dataObj.equipmentCode;
        //	var reg = /^[0-9]{1,25}$/;
        var reg = /^\s*$/g;
        if (reg.test(equipmentCode)) {
            dataObj.equipmentCodeErr = "设备编号不能为空";
            isSubmit = false;
        }
        // var postionCode = dataObj.postionCode;
        // //var reg = /^([0-9A-Fa-f]{2}:){5}(([0-9A-Fa-f]{2}))$/;
        // var reg = /^\s*$/g;
        // if (postionCode.length == 0 && reg.test(postionCode)) {
        //     dataObj.postionCodeErr = "位置编号不能为空";
        //     isSubmit = false;
        // }

        $.ajax({
            url: pageUrl + "check",
            type: "POST",
            dataType: "json",
            data: {postionCode: dataObj.postionCode, equipmentCode: dataObj.equipmentCode, id: dataObj.id},
            cache: false,
            async: false
        }).done(function (res) {
            if (res.resultPostionCode == "noExistentError") {
                dataObj.postionCodeErr = "位置编号已在其它地方使用";
                isSubmit = false;
            } else if (res.resultPostionCode == "nullError") {
                dataObj.postionCodeErr = "位置编号不存在";
                isSubmit = false;
            }
            else if (res.resultEquipmentCode == "errorEquipment") {
                dataObj.equipmentCodeErr = "设备编号已被使用，不能修改操作";
                isSubmit = false;
            } else if (res.resultEquipmentCode == "success") {
                dataObj.equipmentCodeErr = "设备编号是本身，不影响使用";
                isSubmit = true;
            }
        });
        result = customUtils.checkLen(dataObj.status, 1, 1, '设备状态');
        if (result.length != 0) {
            dataObj.statusErr = result;
            isSubmit = false;
        }
        result = customUtils.checkLen(dataObj.installBy, 1, 30, '安装人');
        if (dataObj.installBy && dataObj.installBy.length > 0 && result.length != 0) {
            dataObj.installByErr = "不能超过30位";
            isSubmit = false;
        }
        return isSubmit;
    },
    checkFileType: function () {
        var fileName = $("#file")[0].files[0].name;
        var fileType = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
        if (fileType.toUpperCase() != 'XLSX' && fileType.toUpperCase() != 'XLS') {
            importVue.fileErr = "请选择*.xlsx或者*.xls格式的Excel文件";
            return false;
        }
        return true;
    },
    checkFileType2: function () {
        //没选择文件时
        var result = true;
        if ($("#grant").find("#file1")[0].files.length <= 0) {
            grantVue.$data.file1Err = "请选择导入的授权信息文件";
            result = false;
        } else {
            var fileName1 = $("#file1")[0].files[0].name;
            if (fileName1 != 'deviceInfo.txt') {
                grantVue.$data.file1Err = "请选择本系统导出的deviceInfo.txt文件";
                result = false;
            }
        }
        if ($("#grant").find("#file2")[0].files.length <= 0) {
            grantVue.$data.file2Err = "请选择导入的授权文件";
            result = false;
        } else {
            var fileName2 = $("#file2")[0].files[0].name;
            var fileType2 = fileName2.substr(fileName2.lastIndexOf(".") + 1, fileName2.length);
            if (fileType2.toUpperCase() != 'LIC') {
                grantVue.$data.file2Err = "请选择*.lic或格式的授权文件";
                result = false;
            }
        }
        return result;
    },
    checkFiled: function () {
        if ($("#filed")[0].files.length <= 0) {
            importVue1.fileErr = "请选择导入的设备文件";
            result = false;
        }
        var fileName = $("#filed")[0].files[0].name;
        var fileType = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
        if (fileType.toUpperCase() != 'XLSX' && fileType.toUpperCase() != 'XLS') {
            importVue1.fileErr = "请选择*.xlsx或者*.xls格式的Excel文件";
            return false;
        }
        return true;
    },
    checkFiled1: function () {
        if ($("#filed1")[0].files.length <= 0) {
            importVue2.fileErr = "请选择导入的设备文件";
            result = false;
        }
        var fileName = $("#filed1")[0].files[0].name;
        var fileType = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
        if (fileType.toUpperCase() != 'XLSX' && fileType.toUpperCase() != 'XLS') {
            importVue2.fileErr = "请选择*.xlsx或者*.xls格式的Excel文件";
            return false;
        }
        var val = importVue2.isUploadFace;
        if (importVue2.isUploadFace.length > 0 || importVue2.isUploadScreenshots.length > 0 || importVue2.isUploadEnvironment.length > 0) {
            return true;
        } else {
            importVue2.statusErr = "请至少选择一个图片上传修改控制";
            return false;
        }
    }
};
//绑定列表List---begin----所有的操作都围绕列表展开，新增、更新其他比较独立
var dataList = new Vue({
    el: "#equipmentList",
    data: {
        ids: [],
        pageInfo: {},
        //自定义条件查询---begin--------
        status: "-1",
        key: "",
        all: false,
        currentDate: "",
        province: "",
        city: "",
        area: "",
        volume: "",
        startTime: "",
        shutdownTime: "",
        runStatus: "",
        equipmentSource: "",
        channelBusiness: "",
        agentBusiness: "",
        num: "",
        total: "",
        onlineRate: "",
        msg: {
            sysErrorMsg: "",
            checkErrMsg: "",
            fieldErrMsg: "",
            success: ""
        },
        provinces: [],
        dictBusiness: [],
        citys: [],
        areas: [],
        //自定义条件查询---end--------
        selectIds: [],//多选
        selectedIdx: -1,//保存操作行的索引
        eventSrc: "",//init:页面初始化；search:点击查询；paging:点击翻页；changePageSize:改变页面显示条数
        selectedPageSize: customUtils.pageSize//修改页面数据显示条数
    },
    mounted: function () {
        //初始化页面数据
        this.getList('init');
        this.getAreaData();
        this.getBusinessType();
        this.$data.currentDate = new Date().getTime();
        //this.getStatusByCondition();
    },
    // 在 `methods` 对象中定义方法,如果操作中函数的逻辑比较复杂，必须封装到dictType对象
    methods: {
        selectChkBtn: function (e) {//用于多选事件
            this.selectIds.push($(e.target).val());
        },
        changeTime: function (elem) {
            this.$data[elem.split("-")[0]] = $("#" + elem).val();
        },
        getAreaData: function () {
            this.$http.get("../appInfo/queryAreaTree").then(function (response) {
                console.log(response)
                dataList.$data.provinces = response.body;
                console.log(dataList.$data)
            }, function (res) {

            });
        },
        getBusinessType: function () {
            this.$http.get("../equipment/queryBusinessType").then(function (response) {
                console.log(response)
                dataList.$data.dictBusiness = response.body;
                addOrUpdate.$data.dictBusiness = response.body;
                console.log(addOrUpdate.$data.dictBusiness)
            }, function (res) {

            });
        },
        //搜索、分页列表
        getList: function (eventSrc) {
            //保存事件源
            this.eventSrc = eventSrc;
            //改变页面显示条数
            if (eventSrc == "changePageSize") {
                if (this.pageInfo.pageSize != this.selectedPageSize) {
                    this.pageInfo.pageSize = this.selectedPageSize;
                    $('#pagination').jqPaginator('destroy');
                    eventSrc = 'init';//重新绘制控件
                } else {
                    return;
                }
            }
            var param = {"page": 1, "rows": customUtils.pageSize};
            //初始化时无当前页数，后台有默认第1页，每页10条
            if (this.pageInfo != undefined && this.pageInfo.pageNum != undefined) {
                param["page"] = this.pageInfo.pageNum;
                param["rows"] = this.pageInfo.pageSize;
            }
            this.$data.ids = [];
            //TODO 搜索条件
            param["status"] = this.$data.status;
            param["installBy"] = this.$data.key;
            param["runStatus"] = this.$data.runStatus;
            /*param["id"]=this.id;
            param["mac"]=this.mac;
            param["postionCode"]=this.postionCode;
            param["installDate"]=this.installDate;
            param["createdBy"]=this.createdBy;
            param["createdDate"]=this.createdDate;
            param["updatedBy"]=this.updatedBy;
            param["updatedDate"]=this.updatedDate;
            param["netCode"]=this.netCode;
            */
            param["key"] = this.$data["key"];
            param["param1"] = this.$data["province"] == '' ? "" : this.$data["province"].code;
            param["param2"] = this.$data["city"] == '' ? "" : this.$data["city"].code;
            param["param3"] = this.$data["area"] == '' ? "" : this.$data["area"].code;
            param["status"] = this.$data["status"];
            param["equipmentSource"] = this.$data["equipmentSource"];
            param["channelBusiness"] = this.$data["channelBusiness"];
            param["agentBusiness"] = this.$data["agentBusiness"];
            console.log(param)
            this.$http.post(pageListUrl, param).then(function (response) {
                dataList.pageInfo = response.body.pagination;
                dataList.total = response.body.total;
                dataList.num = response.body.num;
                var onlineRate = Math.round((response.body.num / response.body.total) * 10000) / 100;
                dataList.onlineRate = isNaN(onlineRate) ? 0 : onlineRate;
                customUtils.noData('无数据', dataList.pageInfo.pages);
                //页面初始化、搜索时，才需要执行分页控件
                if (eventSrc == 'init' || eventSrc == 'search') {
                    customUtils.paging('#pagination', dataList.pageInfo.pages, customUtils.showPage, function (num) {
                        //当前页码pageNum与将要翻页的页码num不相等才执行，否则为同一页
                        if (dataList.pageInfo.pageNum != num) {
                            dataList.pageInfo.pageNum = num;
                            dataList.getList('paging');
                        }
                    });
                }
            }, function (response) {
                console.log(response.body);
            });
        }, getStatusByCondition: function () {
            var self = this;
            var param = {};
            param["key"] = this.$data["key"];
            param["param1"] = this.$data["province"] == '' ? "" : this.$data["province"].code;
            param["param2"] = this.$data["city"] == '' ? "" : this.$data["city"].code;
            param["param3"] = this.$data["area"] == '' ? "" : this.$data["area"].code;
            param["runStatus"] = this.$data.runStatus;
            param["equipmentSource"] = this.$data.equipmentSource;
            param["channelBusiness"] = this.$data.channelBusiness;
            param["agentBusiness"] = this.$data.agentBusiness;
            param["status"] = this.$data["status"];
            //发送请求,第一个参数http对象，第二个是url，第三个是参数，第四个是成功回调，第五个是请求失败回调
            customUtils.post(self, pageUrl + "getStatusByCondition", param, function (response, isSuccess) {
                dataList.total = response.body.total;
                dataList.num = response.body.num;
                var onlineRate = Math.round((response.body.num / response.body.total) * 10000) / 100;
                dataList.onlineRate = isNaN(onlineRate) ? 0 : onlineRate;
            }, function (response) {
                console.log(response)
            });
        },
        //更新状态
        updateStatus: function (index) {
            var record = this.pageInfo.list[index];
            var status = record.status == 0 ? 1 : 0;
            var param = {id: record.id, status: status};
            this.$http.post(pageUrl + 'update', param).then(function (response) {
                record.status = status;
                customUtils.showTips(response, null, 1000);
            }, function (response) {
                console.log(response.body);
            });
        },
        debug: function (index) {
            var record = this.pageInfo.list[index];
            console.log(record)
            var debug = record.debug == '1' ? "0" : "1";
            this.$http.post(pageUrl + "debug", {id: record.id, debug: debug}).then(function (response) {
                console.log(response)
                customUtils.showTips(response.body, null, 3000);
                dataList.getList('no');
            });
        },
        updatePhoto: function (index, type) {
            var record = this.pageInfo.list[index];
            switch (type) {
                case '1':
                    var isUploadFace = record.isUploadFace == '1' ? "0" : "1";
                    var param = {id: record.id, isUploadFace: isUploadFace};
                    break;
                case '2':
                    var isUploadScreenshots = record.isUploadScreenshots == '1' ? "0" : "1";
                    var param = {id: record.id, isUploadScreenshots: isUploadScreenshots};
                    break;
                default:
                    var isUploadEnvironment = record.isUploadEnvironment == '1' ? "0" : "1";
                    var param = {id: record.id, isUploadEnvironment: isUploadEnvironment};
            }
            this.$http.post(pageUrl + "updatePhoto", param).then(function (response) {
                console.log(response)
                customUtils.showTips(response.body, null, 3000);
                dataList.getList('no');
            });
        },
        updateClearEquipment: function (index) {
            var record = this.pageInfo.list[index];
            var clearEquipment = record.clearEquipment == '1' ? "0" : "1";
            var param = {id: record.id, clearEquipment: clearEquipment};
            var a = confirm("请谨慎操作，如果开启将清空设备所有缓存广告！");
            if (a) {
                this.$http.post(pageUrl + "updatePhoto", param).then(function (response) {
                    console.log(response)
                    customUtils.showTips(response.body, null, 3000);
                    dataList.getList('no');
                })
            }
        },
        updateFirmwareStatus: function (index) {
            var record = this.pageInfo.list[index];
            var firmwareStatus = record.firmwareStatus == '1' ? "0" : "1";
            var param = {id: record.id, firmwareStatus: firmwareStatus};
            var self = this;
            var msg = "请谨慎操作，如果开启设备固件将会升级！";
            layer.confirm(msg, function (index) {
                customUtils.post(self, pageUrl + "updateFirmwareStatus", param, function (response, isSuccess) {
                    dataList.getList('no');
                }, function (response) {
                    customUtils.showRequestTips(response, 3000)
                });
                layer.close(index);
                return true;
            });
            return false;
        },
        channel: function (index) {
            var record = this.pageInfo.list[index];
            console.log(record)
            this.$http.post(pageUrl + "channel", {id: record.id, channel: record.channel}).then(function (response) {
                console.log(response)
                customUtils.showTips(response.body, null, 3000);
                dataList.getList('init');
            });

        },
        //初始化更新，更新对话框
        updateInit: function (index) {
            //清除表单数据
            $.each(addOrUpdate.$data, function (key) {
                if(key != 'dictBusiness'){
                    addOrUpdate[key] = "";
                }
            });
            var record = this.pageInfo.list[index];
            this.selectedIdx = index;
            var url = pageUrl + 'id/' + record.id;
            this.$http.get(url).then(function (response) {
                //回显表单数据
                $.each(response.body, function (key) {
                    if (addOrUpdate[key] != undefined && response.body[key]) {
                        addOrUpdate[key] = response.body[key];
                    }
                });
            }, function (response) {
                console.log(response);
                customUtils.showRequestTips(response, 3000);
            });
            this.addOrUpdatePanel("update");
        },
        //根据设备id编号
        deleteEQ: function (index) {
            var self = this;
            layer.confirm("你确定要删除这条数据么", function (idx) {
                var record = self.pageInfo.list[index];
                var param = {id: record.id};
                customUtils.post(self, pageUrl + 'deleteEQ', param, function (response, isSuccess) {
                    record.status = status;
                    //根据需要刷新页面数据
                    dataList.getList('no');
                }, function (response) {
                    //console.log(response.body);
                });
                layer.close(idx);
            })
        },
        //打开添加对话框
        addOrUpdatePanel: function (flag) {
            if (flag == "add") {
                //清除表单数据
                $.each(addOrUpdate.$data, function (key) {
                    addOrUpdate[key] = "";
                });
            }
            addPanel = layer.open({
                type: 1,
                title: "添加设备",
                area: ['530px', 'auto'],
                shadeClose: false, // 点击遮罩关闭
                content: $('#addPanel')
            });
        },
        batchUpdateStatus: function (status) {
            console.log(status);
            console.log(this.$data.ids);
            if (this.$data.ids.length <= 0) {
                this.$data.msg.checkErrMsg = "请勾选设备";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
            var a = confirm("你确定要进行操作吗？");
            if (a) {
                this.$http.post(pageUrl + "batch", {"status": status, "ids": this.$data.ids}).then(function (response) {
                    customUtils.showTips(response.body, null, 3000);
                    //初始化搜索条件
                    // this.$data.status = '-1';
                    // this.$data.key = '';
                    dataList.getList('no');
                });
            }
            else if (mymessage == false) {
                return;
            }
        },
        volumeSetVolume: function () {
            console.log(this.$data.ids);
            var self = this;
            if (this.$data.ids.length <= 0) {
                this.$data.msg.checkErrMsg = "请勾选设备";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
            var volume = this.$data.volume;
            var val = volume + "";
            if (val.length > 0) {
                this.$http.post(pageUrl + "setVolumeOrTime", {
                    "volume": volume,
                    "ids": this.$data.ids
                }).then(function (response) {
                    customUtils.showTips(response.body, null, 3000);
                    //初始化搜索条件
                    this.$data.volume = '';
                    this.getList('no');
                });
            } else {
                this.$data.msg.checkErrMsg = "请选择音量";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
        },
        setOnOffTime: function () {
            var self = this;
            if (this.$data.ids.length <= 0) {
                this.$data.msg.checkErrMsg = "请勾选设备";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
            var startTime = this.$data.startTime;
            var shutdownTime = this.$data.shutdownTime;
            if (startTime.length > 0 || shutdownTime.length > 0) {
                this.$http.post(pageUrl + "setVolumeOrTime", {
                    "startTime": startTime,
                    "shutdownTime": shutdownTime,
                    "ids": this.$data.ids
                }).then(function (response) {
                    customUtils.showTips(response.body, null, 3000);
                    //初始化搜索条件
                    this.$data.startTime = '';
                    this.$data.shutdownTime = '';
                    this.getList('no');
                });
            } else {
                this.$data.msg.checkErrMsg = "请选择开机时间或关机时间，或者两者都选";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
        },
        exportHardware: function () {
            if (this.$data.ids.length <= 0) {
                this.$data.msg.checkErrMsg = "请勾选设备";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
            var path = "../equipment/exportHardware?";
            for (var i = 0; i < this.$data.ids.length; i++) {
                var val = this.$data.ids[i];
                path += "ids[]=" + val + "&"
            }
            window.location.href = encodeURI(path.substring(0, path.length - 1));
            dataList.$data.ids = [];
        },
        remote: function (flag) {
            //0:关机 1:重启
            console.log(this.$data.ids);
            if (this.$data.ids.length <= 0) {
                this.$data.msg.checkErrMsg = "请勾选设备";
                customUtils.showTips(this.$data.msg, null, 3000);
                return;
            }
            this.$http.post(pageUrl + "remote", {"flag": flag, "ids": this.$data.ids}).then(function (response) {
                customUtils.showTips(response.body, null, 3000);
                //初始化搜索条件
                dataList.getList('no');
            });
        },
        //全选--取消全选方法
        checkAll: function () {
            var fg = this.$data.all;
            if (fg) {
                this.$data.all = false;
                $("tbody").find("input[type='checkbox'][name='id']").each(function (i, val) {
                    dataList.$data.ids = [];
                });
            } else {
                this.$data.all = true;
                $("tbody").find("input[type='checkbox'][name='id']").each(function (i, val) {
                    dataList.$data.ids[i] = val.value;
                });
            }
            console.log(this.$data.ids)
        },
        setCitys: function () {
            dataList.$data.citys = dataList.$data.province.citys;
            dataList.$data.city = "";
            dataList.$data.area = "";
        },
        setAreas: function () {
            dataList.$data.areas = dataList.$data.city.areas;
            dataList.$data.area = "";
        },
        openImportPanel: function () {
            var obj3 = document.getElementById('file');
            obj3.outerHTML = obj3.outerHTML;
            importVue.fileErr = "";
            importPanel = layer.open({
                type: 1,
                title: "导入设备信息",
                area: ['600px', '70%'],
                shadeClose: false, // 点击遮罩关闭
                content: $('#importPanel')
            });
        },
        postion: function (flag) {
            var obj3 = document.getElementById('file');
            obj3.outerHTML = obj3.outerHTML;
            var title = '';
            if(flag == '1'){
                title = '批量设置设备状态';
                $("#t8").show();
            }else{
                title = '批量撤机';
                $("#t8").hide();
            }
            importVue1.fileErr = "";
            importVue1.type = flag;
            $(".errMsg").html('');
            importPanel1 = layer.open({
                type: 1,
                title: title,
                area: ['600px', '70%'],
                shadeClose: false, // 点击遮罩关闭
                content: $('#importPanel1')
            });
        },
        photo: function () {
            var obj3 = document.getElementById('file1');
            obj3.outerHTML = obj3.outerHTML;
            importVue2.fileErr = "";
            importPanel2 = layer.open({
                type: 1,
                title: "批量设置图片上传",
                area: ['600px', '70%'],
                shadeClose: false, // 点击遮罩关闭
                content: $('#importPanel2')
            });
        },
        importGrantInfo: function () {
            var obj1 = document.getElementById('file1');
            obj1.outerHTML = obj1.outerHTML;
            var obj2 = document.getElementById('file2');
            obj2.outerHTML = obj2.outerHTML;
            grantVue.file1Err = "";
            grantVue.file2Err = "";
            grantPanel = layer.open({
                type: 1,
                title: "导入授权文件",
                area: ['600px', '70%'],
                shadeClose: false, // 点击遮罩关闭
                content: $('#grant')
            });
        }
    },
    filters: {
        // 时间格式化
        timeStamps(StatusMinute) {
            if (StatusMinute == null) {
                return StatusMinute = "一天未在线";
            }
            var day = parseInt(StatusMinute / 60 / 60 / 24)
            var hour = parseInt(StatusMinute / 60 / 60 % 24)
            var min = parseInt(StatusMinute / 60 % 60)
            StatusMinute = ""
            if (day > 0) {
                StatusMinute = day + "天"
            }
            if (hour > 0 && day < 1) {
                StatusMinute += hour + "小时"
            }
            if (min > 0 && day < 1) {
                StatusMinute += parseFloat(min) + "分钟"
            }
            if (min == 0) {
                StatusMinute = "一天未在线"
            }
            return StatusMinute
        }
    }
});
//绑定列表List---end----

//新增或更新---------begin-------
var addOrUpdate = new Vue({
    el: "#addPanel",
    data: {
        ids: [],
        installDate: "",
        installBy: "",
        status: "1",
        dictBusiness: [],
        equipmentSource: "",
        channelBusiness: "",
        agentBusiness: "",
        id: "",
        equipmentCode: "",
        postionCode: "",
        //以下是错误信息
        installDateErr: "",

        installByErr: "",
        statusErr: "",
        postionCodeErr: "",
        equipmentCodeErr: "",
        equipmentSourceErr: "",
        channelBusinessErr: "",
        agentBusinessErr: ""
    },
    methods: {
        changeTime: function (elem) {
            addOrUpdate[elem.split('-')[0]] = $("#" + elem).val();
        },
        save: function () {
            console.log(this.$data)
            // 清除错误信息
            this.$data.installByErr = "",
                this.$data.statusErr = "",
                this.$data.postionCodeErr = "",
                this.$data.equipmentCodeErr = ""
            this.$data.installDate = $("input[name='installDate']").val();
            if (!dictType.checkLogic(this.$data)) {
                return;
            }
            console.log(this.$data);
            //没有id的时候表示新增，否则为更新
            var actionUrl = this.id == "" ? 'save' : 'upEquipment';
            //逻辑校验

            this.$http.post(pageUrl + actionUrl, this.$data).then(function (response) {
                //显示成功或失败信息
                var isSuccess = customUtils.showTips(response.body, addOrUpdate.data, 1000);
                if (actionUrl == 'upEquipment') {
                    var record = dataList.pageInfo.list[dataList.selectedIdx];
                    //更新成功，刷新列表中对应的数据
                    $.each(record, function (key) {
                        if (addOrUpdate[key] != undefined) {
                            record[key] = addOrUpdate[key];
                        }
                    });
                    dataList.getList("no");
                } else if (isSuccess) {
                    dataList.getList('init');
                }
                if (isSuccess && addPanel) layer.close(addPanel);
            }, function (res) {
                //console.log(response.body);
            });
        },
        cancel: function () {
            if (addPanel) layer.close(addPanel);
        }
    }
});
//新增或更新---------end-------

var importVue = new Vue({
    el: "#importPanel",
    data: {
        fileErr: ""
    },
    methods: {
        importEquipment: function () {
            var self = this;

            if (!dictType.checkFileType()) {
                return;
            }
            var formDate = new FormData($("#importPanel")[0]);
            //没选择文件时
            if ($("#importPanel").find("#file")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "upload", formDate, function (response) {
                console.log(response);
                var html = "";

                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    response.body.errList.forEach(function (value, index) {
                        html = html + value + "<br>";
                    });
                    $(".errMsg").html(html);
                } else {
                    //
                    if (importPanel) layer.close(importPanel);
                    dataList.getList('init');
                }
                //非字段错误提示  
                if (response.body.successMsg) {
                    customUtils.tips(response.body.successMsg, 1, 3000);
                } else {
                    customUtils.showTips(response.body, null, 2000);
                }

            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});
var grantVue = new Vue({
    el: "#grant",
    data: {
        file1Err: "",
        file2Err: ""
    },
    methods: {
        importGrant: function () {
            var self = this;

            if (!dictType.checkFileType2()) {
                return;
            }
            var formDate = new FormData($("#grant")[0]);

            customUtils.post(self, pageUrl + "grant", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                // //非字段错误提示
                // if(response.body.successMsg){
                //     customUtils.tips(response.body.successMsg,1,3000);
                // }else {
                //     customUtils.showTips(response.body,null,2000);
                // }
                if (grantPanel) layer.close(grantPanel);
                dataList.getList('init');

            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }

});
var importVue1 = new Vue({
    el: "#importPanel1",
    data: {
        status: "3",
        fileErr: "",
        statusErr: "",
        type: ""
    },
    methods: {
        importA: function () {
            var self = this;
            var actionUrl = importVue1.type == "1" ? 'onupload' : 'downEquipments';
            if (!dictType.checkFiled()) {
                return;
            }
            console.log(status);
            console.log($("#importPanel1"))
            console.log($("#importPanel1").find("#filed")[0].files)
            var formDate = new FormData($("#importPanel1")[0]);
            //没选择文件时
            if ($("#importPanel1").find("#filed")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + actionUrl, formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    response.body.errList.forEach(function (value, index) {
                        html = html + value + "<br>";
                    });
                    $(".errMsg").html(html);
                } else {
                    if (importPanel1) layer.close(importPanel1);
                    dataList.getList('no');
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});
var importVue2 = new Vue({
    el: "#importPanel2",
    data: {
        status: "3",
        fileErr: "",
        statusErr: "",
        isUploadFace: "",
        isUploadScreenshots: "",
        isUploadEnvironment: ""
    },
    methods: {
        importB: function () {
            var self = this;
            if (!dictType.checkFiled1()) {
                return;
            }
            console.log(status);
            console.log($("#importPanel2"))
            console.log($("#importPanel2").find("#filed1")[0].files)
            var formDate = new FormData($("#importPanel2")[0]);
            //没选择文件时
            if ($("#importPanel2").find("#filed1")[0].files.length <= 0) {
                $(".errMsg").html("请选择要上传的数据文件");
                return;
            }
            customUtils.post(self, pageUrl + "onupload", formDate, function (response) {
                console.log(response);
                customUtils.showTips(response.body, null, 2000);
                var html = "";
                if (response.body.errList != 'undefined' && response.body.errList != '' && response.body.errList != null) {
                    response.body.errList.forEach(function (value, index) {
                        html = html + value + "<br>";
                    });
                    $(".errMsg").html(html);
                } else {
                    if (importPanel2) layer.close(importPanel2);
                    dataList.getList('no');
                }
            }, function (response) {
                customUtils.showRequestTips(response, 3000)
            })
            console.log(formDate);
        }
    }
});